home *** CD-ROM | disk | FTP | other *** search
- /* bt_free.c - maintain list of free index blocks */
- #include "stdio.h"
- #include "btree.h"
- #include "bt_macro.h"
-
- #define FREE_LEVEL (-1) /* marks a block as free */
- extern IX_DESC *pci ; /* refers to index descriptor */
- /* for current function call */
-
- extern BLOCK spare_block ; /* scratch block for splits and */
- /* compressing */
-
- int make_free(fstart,filesize) /* set up free block chain */
- RECPOS fstart ; /* first free block */
- RECPOS filesize ; /* size of the index file */
- {
- BLOCK *pb ;
- RECPOS r ;
- pb = & spare_block ; /* scratch block */
- pci->dx.ff = NULLREC ; /* no blocks free to start */
- for(r = fstart ; r < filesize ; r = r + IXB_SIZE )
- { write_free(r,pb) ; }
- }
-
- RECPOS get_free() /* grab a free block for use */
- {
- RECPOS r , rt ;
-
- r = pci->dx.ff ; /* get location of first free block */
- if( r != NULLREC ) /* is there one ? */
- { read_if(r,&rt,sizeof(RECPOS)) ; /* yes - find where it */
- pci->dx.ff = rt ; /* points & make it the 1st free */
- }
- return( r ) ;
- }
-
- int write_free(r,pb) /* write out a free block */
- RECPOS r ; /* record number of block to free */
- BLOCK *pb ; /* use this as scrstch space */
- {
- pb->lvl = FREE_LEVEL ; /* mark block as free */
- clr_mem(pb->entries,0,IXB_SPACE) ; /* zero out the block */
- pb->brec = pci->dx.ff ; /* point to current 1st free block */
- write_block(r,pb) ; /* write the free block */
- pci->dx.ff = r ; /* make this block the first free */
- }
-
-